export const ancientNumberMap: Record<number, string> = {
  0: "0",
  1: "一",
  2: "二",
  3: "三",
  4: "四", //亖 或 "四"
  5: "五",
  6: "六",
  7: "七",
  8: "八",
  9: "九",
  10: "十",
  11: "十一",
  12: "十二",
  13: "十三",
  14: "十四", //十亖 或 "十四"
  15: "十五",
  16: "十六",
  17: "十七",
  18: "十八",
  19: "十九",
  20: "廿",
  21: "廿一",
  22: "廿二",
  23: "廿三",
  24: "廿亖", // 或 "廿四"
  25: "廿五",
  26: "廿六",
  27: "廿七",
  28: "廿八",
  29: "廿九",
  30: "卅",
  31: "卅一",
  32: "卅二",
  33: "卅三",
  34: "卅亖", // 或 "卅四"
  35: "卅五",
  36: "卅六",
  37: "卅七",
  38: "卅八",
  39: "卅九",
  40: "卌",
  41: "卌一",
  42: "卌二",
  43: "卌三",
  44: "卌亖", // 或 "卌四"
  45: "卌五",
  46: "卌六",
  47: "卌七",
  48: "卌八",
  49: "卌九",
  50: "五十",
  51: "五十一",
  52: "五十二",
  53: "五十三",
  54: "五十亖",
  55: "五十五",
  56: "五十六",
  57: "五十七",
  58: "五十八",
  59: "五十九",
  60: "六十",
  61: "六十一",
  62: "六十二",
  63: "六十三",
  64: "六十亖",
  65: "六十五",
  66: "六十六",
  67: "六十七",
  68: "六十八",
  69: "六十九",
  70: "七十",
  71: "七十一",
  72: "七十二",
  73: "七十三",
  74: "七十亖",
  75: "七十五",
  76: "七十六",
  77: "七十七",
  78: "七十八",
  79: "七十九",
  80: "八十",
  81: "八十一",
  82: "八十二",
  83: "八十三",
  84: "八十亖",
  85: "八十五",
  86: "八十六",
  87: "八十七",
  88: "八十八",
  89: "八十九",
  90: "九十",
  91: "九十一",
  92: "九十二",
  93: "九十三",
  94: "九十亖",
  95: "九十五",
  96: "九十六",
  97: "九十七",
  98: "九十八",
  99: "九十九"
};

// 转换世次数字为古代数字表示
export const convertToAncientNumber = (generation: number): string => {
  return ancientNumberMap[generation] || generation.toString();
};

// 转换日期为古代数字格式
export const convertDateToAncient = (dateString: string): string => {
  if (!dateString) return '';

  const date = new Date(dateString);
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();

  const ancientYear = convertNumberToAncient(year);
  const ancientMonth = convertToAncientNumber(month);
  const ancientDay = convertToAncientNumber(day);

  return `${ancientYear}年${ancientMonth}月${ancientDay}日`;
};

// 转换任意数字为古代数字（支持大于99的数字）
const convertNumberToAncient = (num: number): string => {
  if (num <= 99) {
    return ancientNumberMap[num] || num.toString();
  }

  // 处理大于99的数字（主要用于年份）
  const str = num.toString();
  let result = '';

  for (let i = 0; i < str.length; i++) {
    const digit = parseInt(str[i]);
    result += ancientNumberMap[digit] || digit.toString();


  }

  return result;
};
